package agh.tk.markuptranslation.gui;

import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;

public class SaveAsAction extends AbstractAction {
	public SaveAsAction() {
		putValue(NAME, "Save as");
	}

	public static void saveAs() {
		File chosenFile = null;
		JFileChooser fc = Main.fc;
		int returnVal = fc.showSaveDialog(Main.frame);
		if(returnVal == JFileChooser.APPROVE_OPTION) {
			chosenFile = fc.getSelectedFile();
		}
		if(chosenFile != null) {
			SaveAction.saveToFile(Main.getText(), chosenFile);
			Main.setFile(chosenFile);
		}
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		saveAs();
	}
}
